﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="AlimonyClaimData", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(AlimonyClaimData))]
    public class AlimonyClaimDataSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IAlimonyClaimData clazz;
        
        public AlimonyClaimDataSerializer(IAlimonyClaimData clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ObligorDescription");
            if (clazz.ObligorDescription!=null) {
                global::Xtee.Core.SerializationMetadata metaObligorDescription = this.GetMetaData(clazz.ObligorDescription);
                Writer.WriteTypeAttribute(metaObligorDescription.TypeQualifiedName.Namespace, metaObligorDescription.TypeQualifiedName.Name);
                metaObligorDescription.NewSerializer(clazz.ObligorDescription).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ObligorDescription");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("ClaimTotal");
            if (clazz.ClaimTotal!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "AlimonyClaimTotal");
                Writer.WriteString(clazz.ClaimTotal.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ClaimTotal");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Currency");
            if (clazz.Currency!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "Currency");
                Writer.WriteString(clazz.Currency.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Currency");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ObligorDescription") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>AlimonyClaimData>ObligorDescription");
                }
                global::Xtee.Core.SerializationMetadata metaObligorDescription = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IObligorDescription>(Reader, "ObligorDescription", "http://producers.kis.xtee.riik.ee/producer/kis");
                clazz.ObligorDescription = metaObligorDescription.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IObligorDescription>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("ObligorDescription");
                    metaObligorDescription.NewSerializer(clazz.ObligorDescription).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>AlimonyClaimData>ObligorDescription", Reader.LocalName);
            }
            if (Reader.LocalName=="ClaimTotal") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>AlimonyClaimData>ClaimTotal");
                }
                clazz.ClaimTotal = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.AlimonyClaimTotal(Reader.ReadElementString("ClaimTotal"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>AlimonyClaimData>ClaimTotal", Reader.LocalName);
            }
            if (Reader.LocalName=="Currency") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>AlimonyClaimData>Currency");
                }
                clazz.Currency = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.Currency(Reader.ReadElementString("Currency"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>AlimonyClaimData>Currency", Reader.LocalName);
            }
        }
    }
}
